package com.sgb.zhaocai.utils;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import com.sgb.link.router.PathLogin;
import com.sgb.zhaocai.base.BaseApi;
import com.sgb.zhaocai.view.demand.activity.DemandOfferActivity;
import com.sgb.zhaocai.view.demand.activity.ProjectIssueActivity;
import com.swgk.core.view.pop.HomeZhaoCaiPublishMenuPop;
import com.swgk.core.common.utils.ActivityJump;
import com.swgk.core.recyclerview.entity.PublishMenuEntity;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;
import java.util.ArrayList;
import java.util.List;

public class PickUtil {

    private static HomeZhaoCaiPublishMenuPop homezhaocaipublishmenupop;

    /**
     * 招标竞价底部弹窗
     */
    public static void showBottomZhaoCaiDialog(Context context) {
        List<PublishMenuEntity> list = new ArrayList<>();
        list.add(new PublishMenuEntity("4", "招", "招标发布"));
        list.add(new PublishMenuEntity("5", "竞", "竞价发布"));
        list.add(new PublishMenuEntity("3", "拍", "拍卖发布"));
        list.add(new PublishMenuEntity("1", "项", "项目发布"));
        homezhaocaipublishmenupop = new HomeZhaoCaiPublishMenuPop(context, null);
        homezhaocaipublishmenupop.setData(list);
        homezhaocaipublishmenupop.setDialogClickCallBack(new HomeZhaoCaiPublishMenuPop.DialogClickCallBack() {
            @Override
            public void onItemClick(String name) {
                //0个人 1企业 2团队
                int type = SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0);
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    ActivityJump.startActivity(PathLogin.VerificationCodeLoginActivity);
                } else {
                    switch (name) {
                        case "项目发布"://项目发布
                            if (type == 1) {
                                context.startActivity(new Intent(context, ProjectIssueActivity.class).putExtra("type", 2));
                            } else {
                                MToast.showToast(context, "请切换至企业身份进行项目发布");
                            }
                            break;
                        case "拍卖发布"://拍卖发布
                            if (type == 1) {
                                BaseApi.getInstance().startAuctionPublish(context, 101);
                            } else {
                                MToast.showToast(context, "请切换至企业身份进行需求发布");
                            }
                            break;
                        case "招标发布": //供方发起
                            MToast.showToast(context, "移动端暂不支持发布招标，请前往电脑端`经营帮/用户中心/招采经营`发布招标信息");
                            break;
                        case "竞价发布": //供方发起
                            MToast.showToast(context, "移动端暂不支持发布竞价，请前往电脑端`经营帮/用户中心/招采经营`发布竞价信息");
                            break;
                    }
                }
            }
        }).show();
    }

    //跳转到需求预告报价界面
    public static void startDemandOffer(Context context, String id, String type, String no, String acttype) {
        //判断是否登录
        if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
            ActivityJump.startActivity(PathLogin.VerificationCodeLoginActivity);
        } else {
            if (SharedPreferenceUtil.getInstance().getSaveBooleanData(SharedPreferenceUtil.PERSON_AUTH, false)) {
                String companyNo = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, "");
                if (TextUtils.isEmpty(no) || !companyNo.equals(no)) {
                    DemandOfferActivity.start(context, id, type, acttype);
                } else {
                    MToast.showToast(context, "不能对本公司发布需求进行报价！");
                }
            } else {
                MToast.showToast(context, "请实名认证后再进行报价");
            }

        }
    }

}
